home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / General / Toolbar Manager 1.0 / TB Tech Docs < prev    next >
Text File  |  1993-06-12  |  8KB  |  258 lines

  1. ToolBar Manager Documentation
  2. © Copyright 1993 SNR Enterprises.
  3. by Narayan Sainaney
  4. 3480 Carnarvon Avenue,
  5. North Vancouver, BC,
  6. V7N 3K9
  7. CANADA
  8.  
  9. What is the ToolBar Manager?
  10.     Well, here's one of those rare situations where it's ok to run the application before reading the read-me file. If you already have, the ToolBar manager is a set of routines that allow you to create toolbars like the ones you saw in the sample applications. The ToolBar Manager takes care of everything from creating the bar to handling user interactions which means you will not have to go through all the calculations I have had to do in the past few days.
  11.  
  12. What it requires?
  13.     The ToolBar manager uses QDOffscreen and Suite Icons (APDA Tech note# 306) so System 7 and Color QuickDraw is a requirement. As for RAM, requirements, that depends on how many "cells" you need to have on the bar. This is basically a trial and error thing. 
  14.  
  15. ToolBar lingo and parts.
  16.     The ToolBar is made up of 2 parts that are closely linked together. The bar and the scrolling region. The bar is made up of cells that hold icons or picts. The scroll region has a thumb that is used for scrolling. The bar and the scroll can be anywhere in a window as long as they are within the same window.
  17.  
  18. ToolBar data.
  19.     There is one data structure that controls all aspects of a ToolBar. The TBHandle:
  20.  
  21. TBHandle^ = TBPtr
  22. TBPtr^ =ToolBar
  23. ToolBar = record
  24.     theWindow: WindowPtr;
  25.     theBar : CGrafPtr;
  26.     theScroll: CGrafPtr;
  27.     theBRect: Rect;
  28.     theSRect: Rect;
  29.     theVRect: Rect;
  30.     theVSRect: Rect;
  31.     thumbRect: Rect;
  32.     depth: Integer;
  33.     cells: Integer;
  34.     offset: Integer;
  35.     toffset: Integer;
  36.     inset: integer;
  37.     bkColor: RGBColor;
  38.     bwColor: Integer;
  39.     Cqd: Boolean;
  40.    end;
  41.  
  42.     It is recommened that you do not access any of the fields directly. Instead use the routines discussed below. 
  43.  
  44. • Creating a ToolBar
  45.  function TBCreate (aWindow, bRect, sRect, cells, inset, depth, cTab, cellP, scrollP, bkColor, bwColor): TBHandle;
  46.  
  47. aWindow
  48. WindowPtr of the Window which holds the ToolBar.
  49.  
  50. bRect
  51. Rect of the bar. (local coordinates)
  52.  
  53. sRect
  54. Rect of the scroll region. (local coordinates)
  55.  
  56. cells
  57. Integer. Number of cells to create.
  58.  
  59. inset
  60. Integer. Inset of each cell to invert when user clicks in it.
  61.  
  62. depth
  63. Integer. Bit depth of ToolBar (0,1,2,4,8,24 or 32. 0 is best)
  64.  
  65. cTab
  66. CTabHandle. Handle to color table for bar and scroll regions. Best to use windows color table.
  67.  
  68. cellP
  69. PicHandle. Handle to PICT to represent an empty cell.
  70.  
  71. scrollP
  72. PicHandle. Handle of PICT to be used a thumb in scroll region.
  73.  
  74. bkColor
  75. RGBColor. Color of background of bar and scroll region.
  76.  
  77. bwColor
  78. Integer. Color will be used if machine does not have Color QuickDraw.
  79.  
  80. returns:
  81. Allocates space for and returns a TBHandle. Returns nil if error occured.
  82.  
  83. notes:
  84.     It is best that you make a PICT resource that holds the cell and thumb and make sure that the vertical size of bRect and sRect is that of the PICTs so that they will not have to be scalled. If so, they are only scalled vertically and not horiozontally.
  85.  
  86. • Drawing a toolbar.
  87.  procedure TBDraw (theToolBar);
  88.  
  89. theToolBar
  90. TBHandle. Will draw the bar and scroll regions in the window the TBHandle is linked to (with TBCreate.)
  91.  
  92. notes:
  93.     Call this whenever you which to draw the whole bar and scroll region (like in an update procedure). 
  94.  
  95. • Re-Drawing an individual cell.
  96.  procedure TBUpdateCell (theToolBar, theCell);
  97.  
  98. theToolBar
  99. TBHandle. 
  100.  
  101. theCell
  102. Integer. Cell number to redraw.
  103.  
  104. notes:
  105.     Call this procedure if you wich to redraw the contents of a cell after you have made changes to it (see below how to do this.) It is better to call this as it updates an individual cell instead of the whole bar and scroll region, hence, reducing flicker.
  106.  
  107. • Plotting an ICN# into a cell
  108.  
  109.  function TBPlotIcon (theToolBar, theCell, theIconID, theTransform, allignment): OsErr;
  110.  
  111.  
  112. theToolBar
  113. TBHandle.
  114.  
  115. theCell.
  116. Integer. Cell to plot icon into.
  117.  
  118. theIconID.
  119. Integer. ID of ICN# resource. (see below)
  120.  
  121. theTransform
  122. Integer. Transformation to be applied.
  123.  
  124. allignment
  125. Integer. Allignment of icon. (see below)
  126.  
  127. notes:
  128.     This call basically calls PlotIconID (described in detail in APDA Tech Note 306) and returns the error encountered by the call to PlotIconID. The 'theTransform' and 'allignment' parameters are as follows:
  129.  
  130. theTransform:
  131.  ttNone = $0000;
  132.  ttDisabled = $0001;
  133.  ttOffline = $0002;
  134.  ttOpen = $0003;
  135.  ttSelected = $4000;
  136.  ttSelectedDisabled = ttSelected + ttDisabled;
  137.  ttSelectedOffline = ttSelected + ttOffline;
  138.  ttSelectedOpen = ttSelected + ttOpen;
  139.  
  140. allignment:
  141.  aNone = $00;
  142.  aVerticalCenter = $01;
  143.  atTop = $02;
  144.  atBottom = $03;
  145.  aHorizontalCenter = $04;
  146.  atLeft = $08;
  147.  atRight = $0C;
  148.  
  149. To center an icon, pass aVerticalCenter + aHorizontalCenter. Call TBDraw or TBUpdateCell for changes to take effect.
  150.  
  151. • Plotting a PICT into a cell.
  152.  
  153.  procedure TBPlotPict (theToolBar, theCell, thePic);
  154.  
  155. theToolbar
  156. TBHandle.
  157.  
  158. theCell
  159. Integer. Cell to draw PICT into.
  160.  
  161. thePic
  162. PicHandle. PICT to be drawn into cell.
  163.  
  164. notes:
  165.     The PICT will be drawn into the cell EXCLUDING the inset. It will also be centered. This can be used to erase a cell by passing the empty cell pict to the call. Call TBDraw or TBUpdateCell for changes to take effect.
  166.  
  167. • Drawing into a cell.
  168.  
  169.  function TBGetCellRect (theToolBar; theCell);
  170.  
  171. theToolBar
  172. TBHandle
  173.  
  174. theCell
  175. Integer. Cell number.
  176.  
  177. returns:
  178. A RECT. This is the bounds rect of the cell. You may use this RECT to use calls like CopyBits, DrawPicture etc etc.
  179.  
  180. notes:
  181.     This call is to be used to get the RECT of a given cell (without inset). The port holding the cells is "theBar" field of the TBHandle. This is the only time you should access/modify any field of the TBHandle. Be sure to call HLock to lock the TBHandle before dereferencing it. Call TBDraw or TBUpdateCell for changes to take effect.
  182.  
  183. • Plotting a PICT/ICN# with CopyDeepMask.
  184.  
  185.  procedure TBDimPict (theToolBar, theCell, thePic, theIcon, allignment, dimBy, doMask);
  186.  
  187. theToolBar
  188. TBHandle.
  189.  
  190. theCell
  191. Cell to apply CopyDeepMask to.
  192.  
  193. thePic
  194. PicHandle. Pict to plot into cell.
  195.  
  196. theIcon.
  197. Integer. If PicHandle is nil, TBDimPict looks for this ICN# to plot (PlotIconID).
  198.  
  199. allignment.
  200. Integer. allignment of ICN# (if PicHandle is nil).
  201.  
  202. dimBy.
  203. RGBColor. Color used for blending with CopyDeepMask.
  204.  
  205. doMask.
  206. Boolean. If true, TBDimPict will calculate a mask using BitMapToRegion and pass it to CopyDeepMask.
  207.  
  208. notes:
  209.     This call allows you to create neat effects like a dimmed icon (see sample code and application). It draws the PICT/ICN# with the inset taken into consideration. Call TBDraw or TBUpdateCell for changes to take effect.
  210.  
  211.  
  212. • Clearing a cell.
  213.  
  214.  procedure TBClearCell (theToolBar; theCell);
  215.  
  216. theToolBar
  217. TBHandle.
  218.  
  219. theCell
  220. Integer. Cell to clear.
  221.  
  222.     This call "clears" a cell by painting the cell with the RGBColor passed to TBCreate. Call TBDraw or TBUpdateCell for changes to take effect.
  223.  
  224. • Handling clicks in bar/scroll region.
  225.  
  226.  function TBClick (theToolBar; theClick): integer;
  227.  
  228. theToolBar
  229. TBHandle.
  230.  
  231. theClick
  232. Point. Point where click initiated (local coordinates!)
  233.  
  234. returns:
  235. Cell that was clicked in or -1 if scrolling occured or the user dragged the mouse out of the cell before letting go.
  236.  
  237. notes:
  238.     Call this function each time in your event loop for each ToolBar. You do not have to check to see if the user did indeed click in a bar or scroll region. It does nothing if the click was not in the toolbar. Otherwise, it handles all the scrolling, hiliting/unhiliting etc and returns control when the mouse is released. The call repeatedly calls GetMouse to track the mouse. It takes care of setting the port to the toolbar's window and re-sets the original port on exit. If the call returns a number other than -1, it is up to you to take action.
  239.  
  240. • Moving/Resizing a bar/scroll area.
  241.  
  242.  procedure TBGrowBar (theToolBar, newVRect, newSRect);
  243.  
  244. theToolbar
  245. TBHandle
  246.  
  247. newVRect
  248. Rect. The new rect (In local coordinates) of the bar. 
  249.  
  250. newSRect
  251. Rect. The new rect (In local coordinates) of the scroll area.
  252.  
  253. notes
  254.     This call takes care of recalculating the new thumb locations etc for a toolbar. It is up to you to erase the original bar and scroll areas and you have to call TBDraw for changes to take effect (TBUpdateCell will not do here).
  255.  
  256. That is all there is to the ToolBar manager. The ToolBar Manager is not free. Read the 'License agreement' documentation for further information.
  257.  
  258.